﻿using System.Collections.Generic;
using CI.Models;
using CI.Services;
using CI.ViewModels.Interfaces;
using Microsoft.Practices.ServiceLocation;

namespace CI.ViewModels.Diagramming
{
    public class DiagramLayoutOptionsViewModel : ModelBase, IDiagramLayoutOptionsViewModel
    {
        public string GroupName { get; set; }

        private readonly IDiagrammingServiceViewModelSide _diagrammingService =
            ServiceLocator.Current.GetInstance<IDiagrammingServiceViewModelSide>();

        private readonly string _layoutOptions;
        private bool _redrawOnChange;
        private string _selectedAlgorithm;
        private bool _sizeToFit;

        public DiagramLayoutOptionsViewModel(string groupName)
        {
            SelectedAlgorithm = "Tree";
            GroupName = groupName;
            StartModel();
        }

        private readonly string[] _layoutAlgorithms = new[]
                                                          {
                                                              "Circular", "Tree", "FR", "BoundedFR", "KK", "ISOM", "LinLog"
                                                              , "EfficientSugiyama", "CompoundFDP"
                                                          };

        public IEnumerable<string> Algorithms
        {
            get { return _layoutAlgorithms; }
        }

        public string SelectedAlgorithm
        {
            get { return _selectedAlgorithm; }
            set { SetField(ref _selectedAlgorithm, value, () => SelectedAlgorithm, Redraw); }
        }

        public void Redraw()
        {
            GraphLayoutAlgorithmSettings settings = CreateLayoutSettings();
            _diagrammingService.ForceLayout(settings);
        }

        public GraphLayoutAlgorithmSettings CreateLayoutSettings()
        {
            return new GraphLayoutAlgorithmSettings {AlgorithmTypeName = SelectedAlgorithm};
        }

        public bool CanRedraw()
        {
            return true;
        }
    }
}